//
//  UserListViewController.m
//  UI_豆瓣项目
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 关业达. All rights reserved.
//

#import "UserListViewController.h"
#import "LoginViewController.h"
#import "SCDataViewController.h"
@interface UserListViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)UITableView *myTableView;


@end

@implementation UserListViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0.643 green:0.592 blue:0.986 alpha:1.000];
    self.navigationItem.title = @"用户";
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"登陆" style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)];
   // 创建TableView
    self.myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    [self.view addSubview:self.myTableView];
    [_myTableView release];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    
}

// 区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
// 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}
// 内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        cell.textLabel.text = @"我的活动";
    }
    if (indexPath.section == 0 && indexPath.row == 2) {
        cell.textLabel.text = @"我的电影";
    }
    if (indexPath.section == 0 && indexPath.row == 3) {
        cell.textLabel.text = @"清除缓存";
    }
    
    return cell;
    
    
}

//点击cell触发方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 1){
        SCDataViewController *scdVC = [[SCDataViewController alloc] init];
        [self.navigationController pushViewController:scdVC animated:YES];
    }
    
    
}





- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"name"];
    if ([string isEqualToString:self.loginview.userTextField.text]) {
        self.navigationItem.rightBarButtonItem.title = @"注销";
    }else{
        self.navigationItem.rightBarButtonItem.title = @"登陆";
    }
}









- (void)rightAction:(UIBarButtonItem *)btn
{
    LoginViewController *loginVC = [[LoginViewController alloc] init];
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:loginVC];
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"name"];
    NSLog(@"string ====== %@", string);
    if (![string isEqualToString:@""]) {
        [[NSUserDefaults standardUserDefaults] setValue:@"" forKey:@"name"];
    }
//    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"name"] isEqualToString:self.loginview.userTextField.text]) {
//        [[NSUserDefaults standardUserDefaults] setValue:@"" forKey:@"name"];
//    }
    
    [self presentViewController:naVC animated:YES completion:^{
        
        
    }];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
